﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using System.Text;

namespace WebUI.LabManage
{
    public partial class RepairRecord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridBind();
        }

        private void GridBind(string strWhere = "")
        {
            Grid1.DataSource = BLL.EquipmentRecord.Repair.GetList(strWhere);
            Grid1.DataBind();
        }
        private void InitForm()
        {
            tb_allower.Text = "";
            tb_RepairCause.Text = "";
            dp_dateDOWN.SelectedDate = null;
            dp_dateUP.SelectedDate = null;
        }
        protected void bnSearch_Click(object sender, EventArgs e)
        {
            if (tb_allower.Text.Trim() == "" && tb_RepairCause.Text.Trim() == "" && dp_dateDOWN.SelectedDate == null && dp_dateUP.SelectedDate == null)
            {
                ExtAspNet.PageContext.RegisterStartupScript(Alert.GetShowInTopReference("你没有输入任何查询条件", "提示！", MessageBoxIcon.Warning));
            }
            else
            {
                StringBuilder strWhere = new StringBuilder();
                if(tb_allower.Text != "")
                {
                    strWhere.AppendFormat(" allower LIKE '%{0}%'",tb_allower.Text);
                }
                if (tb_RepairCause.Text != "")
                {
                    if (tb_allower.Text != "")
                    {
                        strWhere.Append(" AND");
                    }
                    strWhere.AppendFormat(" RepairCause LIKE '%{0}%'",tb_RepairCause.Text);
                }
                if (dp_dateUP.SelectedDate != null)
                {
                    if (tb_allower.Text != "" || tb_allower.Text != "")
                    {
                        strWhere.Append(" AND");
                    }
                    strWhere.AppendFormat(" reportDate >= '{0}'",dp_dateUP.SelectedDate);
                }
                if (dp_dateDOWN.SelectedDate != null)
                {
                    if (tb_allower.Text != "" || tb_allower.Text != "" || dp_dateUP.SelectedDate != null)
                    {
                        strWhere.Append(" AND");
                    }
                    strWhere.AppendFormat(" reportDate <= '{0}'",dp_dateDOWN.SelectedDate);
                }
                GridBind(strWhere.ToString());
            }
        }
        protected void bnReset_Click(object sender, EventArgs e)
        {
            GridBind();
            InitForm();

        }
        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }
    }
}